package com.langfeiyes.test;

import java.util.ArrayList;
import java.util.List;
import java.util.function.Function;
import java.util.stream.Collectors;

public class App {

    public static List<Catalog> getData(){
        List<Catalog> list = new ArrayList<>();

        list.add(new Catalog(1L, "gz1", 1L, "广州"));
        list.add(new Catalog(2L, "gz2", 1L, "广州"));
        list.add(new Catalog(3L, "gz3", 1L, "广州"));
        list.add(new Catalog(4L, "bj1", 2L, "北京"));
        list.add(new Catalog(5L, "bj2", 2L, "北京"));
        list.add(new Catalog(6L, "bj3", 2L, "北京"));
        list.add(new Catalog(7L, "sh1", 3L, "上海"));
        list.add(new Catalog(8L, "sh2", 3L, "上海"));
        list.add(new Catalog(9L, "sh3", 3L, "上海"));

        return list;



    }


    public static void main(String[] args) {
        List<Catalog> data = getData();

        List<CatalogVO> vos = new ArrayList<>();
        List<CatalogVO> collect = data.stream().map(catalog -> catalog.getDestName()).distinct()
                .map(destName -> {
                    CatalogVO catalogVO = new CatalogVO();
                    catalogVO.setDestName(destName);
                    List<String> list = catalogVO.getCatalogList();
                    data.forEach(catalog -> {
                        if (catalog.getDestName().equals(destName)) {
                            list.add(catalog.getName() + "——" + catalog.getId());
                        }
                    });
                    vos.add(catalogVO);
                    return catalogVO;
                }).collect(Collectors.toList());

        collect.forEach(System.out::println);


    }
}
